import org.w3c.dom.Node;

/**
 * @author SaoE
 * @date 2025/3/20 11:47
 */
public class myHashMap {

    public class MyHashMap {
        private final int length = 10;
        private int size = 0;
        private int hash(Integer key) {
            return key == null ? 0 : key % length;
        }

        public class Node {
            private int key;
            private int value;
            private Node next;
            private Node(int key, int value) {
                this.key = key;
                this.value = value;
            }
        }
        private Node[] table = new Node[length];
        public void put(int key, int value) {
            int index = key % length;
            Node node = table[index];
            while (node != null) {
                if (node.key == key) {
                    node.value = value;
                    return;
                }
                node = node.next;
            }
            Node newNode = new Node(key, value);
            newNode.next = table[index];
            table[index] = newNode;
            size++;
        }
        public int get(int key) {
            int index = key % length;
            Node node = table[index];
            while (node != null) {
                if (node.key == key) {
                    return node.value;
                }
                node = node.next;
            }
            return -1;
        }
        public void remove(int key) {
            int index = key % length;
            Node node = table[index];
            Node pre = null;
            while (node != null) {
                if (node.key == key) {
                    if (pre == null) {
                        table[index] = node.next;
                    } else {
                        pre.next = node.next;
                    }
                    size--;
                    return;
                }
                pre = node;
                node =node.next;
            }
        }
        public int size() {
            return size;
        }

    }

}
